package com.cpf.springboot;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class RetryService {
    private int counter = 0;
    private final SayHello sayHello;

    @Autowired
    public RetryService(SayHello sayHello) {
        this.sayHello = sayHello;
    }

    @Retryable(value = RuntimeException.class, maxAttempts = 3)
    public void retry() {
        log.info("result: {}", sayHello.sayHello());
        log.info("retry count: {}", ++counter);
        throw new RuntimeException();
    }
}
